package de.slothsoft.commons.swing;

import java.util.Comparator;

import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import de.slothsoft.commons.DisplayableComparator;
import de.slothsoft.commons.IDisplayable;

public class DisplayableTableRowSorter<M extends TableModel> extends
		TableRowSorter<M> {

	public DisplayableTableRowSorter() {
		super();
	}

	public DisplayableTableRowSorter(M model) {
		super(model);
	}

	@Override
	public Comparator<?> getComparator(int column) {
		Class<?> columnClass = getModel().getColumnClass(column);
		if (IDisplayable.class.isAssignableFrom(columnClass)) {
			return new DisplayableComparator();
		}
		return super.getComparator(column);
	}
}
